import java.util.*;
import java.sql.*;
import javax.sql.RowSet;
import java.io.*;

import com.mysql.jdbc.Driver;

public class TestMySqlConnection {

    public static void main(String[] args) { 

	String dataBaseName     = "jdbc:mysql://127.0.0.1/web";
	String dbDriverName     = "com.mysql.jdbc.Driver";
	String userName         = "root";
	String password         = "Cft6yhNji9";
        
	try { 
            Class.forName(dbDriverName).newInstance(); 
	    Connection con = DriverManager.getConnection(dataBaseName, userName, password);
	    Statement stmt = con.createStatement();
	    ResultSet res  = stmt.executeQuery("SELECT * FROM subject;");
	    ResultSetMetaData rsmd = res.getMetaData();
	    int number_of_colums = rsmd.getColumnCount();
	   
	    for (int i=1; i <= number_of_colums; ++i) {
		System.out.println(rsmd.getColumnName(i));
		System.out.println(rsmd.getColumnTypeName(i));
		System.out.println(""+rsmd.getColumnDisplaySize(i));
	    }
	    stmt.close();
	    con.close();

        } catch (SQLException ex) {
            System.out.println("SQLException: " + ex.getMessage()); 
            System.out.println("SQLState: " + ex.getSQLState()); 
            System.out.println("VendorError: " + ex.getErrorCode()); 
        }
        catch (Exception e) { 
	    System.out.println(e);
        }
    }
}

